<?php 
include "includes/request.class.php"; 

/**
 * This file acts as a mediator between the URL handler (.htaccess) and
 * the response object (request.class.php)
 *
 * All URLs are caught and pre-processed in the handler and then given to
 * this document. This document will sort the data, decide which function
 * is going to be called, create the request object and then set atributes
 * on that object. Once the function is called on the request object it will
 * process all data internally coming to an end by responding to the user
 * appropriatly.
 *
 */

$perm       = $_GET["perm"];
$type       = $_GET["type"];
$arg        = $_GET["arg"];
$callback   = $_GET["callback"];
// latitude and longitude for closest()
$lat        = $_GET["lat"];
$long       = $_GET["long"];
// start and stop nodes for pathing function
$start      = $_GET["start"];
$stop       = $_GET["stop"];
// arguments for object
$debug      = $_GET["debug"];
$minimal    = $_GET["minimal"];
$order      = $_GET["order"];
$category   = $_GET["category"];
$id         = $_GET["destination"];

// Used to build the function type
$method = $_SERVER["REQUEST_METHOD"];
// if the requested function is empty, load help function
$func   = (isset($_GET["function"]) && $_GET["function"] != "docs" ) ? $_GET['function']: "help";
$function = strtolower("${method}${func}");

// create object
$r = new Request($perm,$method,$type);

// is debug argument set? if so enable in object
if($debug == true) { $r->debug = true; }
// is minimal argument set? if so enable in object
if($minimal == true) { $r->minimal = true; }
// is order argument set? if so set in object
if($order == "name") { $r->order = "name"; }
// is callback argument set? if so set in object
if(!empty($callback)) { $r->callback = $callback; }
// is category argument set? if so set in object
if(!empty($category)) { $r->category = addslashes($category); }
// is destination argument set? if so set in object
if(!empty($id)) { $r->destination = addslashes($id); }

if( !empty($lat) && !empty($long) ) {
    $r->$function(array($lat,$long));
} else if( !empty($start) && !empty($stop) ) {
    $r->$function(array($start,$stop));
} else {
    $r->$function($arg);
}
?>
